function Archive(layui) {
    this.table = layui.table;
    this.$ = layui.$;
    this.form = layui.form;
    this.func = layui.func;
    this.admin = layui.admin;
    this.util = layui.util;
    this.tableId = "archive";
    var that = this;

    /**
     * 档案资料信息表管理
     */

    /**
     * 初始化表格的列
     */
    this.initColumn = function () {
        return [[
            {type: 'radio',fixed:'left'},
            {field: 'id', hide: true, title: 'id'},
            {field: 'wjid', sort: true, title: '卷宗号'},
            {field: 'mc', sort: true, title: '档案名称'},
            {field: 'dalx', width:120,sort: true, title: '档案类型',templet:'#dalx'},
            {field: 'ssrrmc', sort: true, title: '所属人'},
            {field: 'mj', sort: true, title: '密级',templet:'#mj'},
            {field: 'glnx', width:120,sort: true, title: '管理年限',templet:'#glnx'},
            {field: 'nd',sort: true, title: '年度'},
            {field: 'qsnd',width:120, sort: true, title: '起始年度'},
            {field: 'jsnd',width:120, sort: true, title: '结束年度'},
            {field: 'ly', sort: true, title: '来源',templet:'#ly'},
            // {field: 'sfyx', sort: true, title: '是否有效',templet:'#sfyx'},
            {fixed:'right',width:120,align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };


    // 渲染表格
    this.tableResult = this.table.render({
        elem: '#' + this.tableId,
        page: false,
        url: Feng.ctxPath + '/archiveInfo/list',
        height: "500",
        where:{'createdDate':this.util.toDateString(new Date())},
        toolbar: '#toolbar',
        defaultToolbar: [],
        cellMinWidth: 100,
        cols: this.initColumn(),
        done:function (res, cur,count) {
            if (cur == 1) {
                var selector = ".layui-table-view[lay-id='"+that.tableId+"'] .layui-table-body tr[data-index=0] .layui-form-radio";
                that.$(selector).click();
            }
        }
    });



    /**
     * 弹出添加对话框
     */
    this.openAddDlg = function () {
        this.admin.putTempData("formData",this.form.val('archiveForm'));
        this.func.open({
            height: 600,
            width: 600,
            title: '添加档案',
            content: Feng.ctxPath + '/archiveInfo/add2',
            tableId: that.tableId
        });
    };


    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    this.openEditDlg = function (data) {
        this.func.open({
            height: 600,
            width: 600,
            title: '编辑档案',
            content: Feng.ctxPath + '/archiveInfo/edit2?id=' + data.id,
            tableId: that.tableId
        });
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    this.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/archiveInfo/delete", function (data) {
                Feng.success("删除成功!");
                that.table.reload(that.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };


    // 工具条点击事件
    this.table.on('toolbar(' + this.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'add') {
            that.openAddDlg();
        }
    });


    // 工具条点击事件
    this.table.on('tool(' + this.tableId + ')', function (obj) {
        var layEvent = obj.event;
        var data = obj.data;
        if (layEvent === 'edit') {
            that.openEditDlg(data);
        } else if (layEvent === 'delete') {
            that.onDeleteItem(data);
        }
    });

    this.callback = null;
    this.setItemSelect = function (callback) {
        this.callback = callback;
        this.table.on('row(' + this.tableId + ')', function (obj) {
            callback(Feng.index(obj), obj.data);
        })
    }


}


